package com.secsys.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;

import org.apache.commons.lang.time.DateUtils;

import com.secsys.dto.BbsModuleDTO;
import com.secsys.dto.InitModuleCountInfoDTO;
import com.secsys.dto.InitModuleDTO;
import com.secsys.dto.InitParentModuleDTO;
import com.secsys.dto.ModuleBean;
import com.secsys.model.TbBbsModule;
import com.secsys.model.TbBbsPost;
import com.secsys.model.TbBbsReply;
import com.secsys.model.TbSysRole;
import com.secsys.model.TbSysUser;
import com.secsys.service.BbsModuleService;
import com.secsys.service.RoleService;
import com.secsys.service.UserService;
import com.secsys.util.Constant;
import com.secsys.util.DateFormatUtils;
import com.secsys.util.MySqlUtil;

/**
 * @Description BBS模块业务接口实现类
 * @author LiusQ
 * @Date 2011-4-9 2:49
 * @version 1.0
 * 
 */
public class BbsModuleServiceImpl extends ServiceImpl<TbBbsModule, Integer>
		implements BbsModuleService {
	/**
	 * @Description 通过module父模块代码查找对应的子模块
	 * 
	 */

	public List<BbsModuleDTO> getChildModule(String parent, String statue) {
		// TODO Auto-generated method stub

		String hql = "from TbBbsModule as tbm where tbm.parent=? and tbm.statue=?";
		List<BbsModuleDTO> conList = null;
		List childModule = this.dao.find(hql, new Object[] { parent, statue });
		if (childModule != null && childModule.size() != 0) {
			conList = new ArrayList<BbsModuleDTO>();
			forEach(childModule, conList);
			return conList;
		} else
			return conList;
	}

	/**
	 * @Description 通过ID、 模块状态、是否为父模块获取相关信息
	 */
	@Override
	public List<TbBbsModule> getChileModule(String moduleNo, String isParent,
			String statue) {
		// TODO Auto-generated method stub

		return null;
	}

	public List queryChildModule(String parent, String statue) {
		// TODO Auto-generated method stub

		String hql = "from TbBbsModule as tbm where tbm.parent=? and tbm.statue=?";

		List childModule = this.dao.find(hql, new Object[] { parent, statue });

		return childModule != null && childModule.size() > 0 ? childModule
				: null;
	}
  
	public List queryChildModules(String parent) {
		// TODO Auto-generated method stub

		String hql = "from TbBbsModule as tbm where tbm.parent=? ";

		List childModule = this.dao.find(hql, new Object[] { parent});

		return childModule != null && childModule.size() > 0 ? childModule
				: null;
	}
	
	/**
	 * @Description 查看指定父模块信息
	 * @param moduleName
	 *            模块名字
	 * @param statue
	 *            模块状态
	 * @return
	 */

	public TbBbsModule getModule(String moduleName, String statue) {
		String hql = "from TbBbsModule as tbm where tbm.moduleName=? and tbm.statue=?";
		List moduleList = this.dao.find(hql,
				new Object[] { moduleName, statue });

		if (moduleList != null && moduleList.size() != 0)
			return (TbBbsModule) moduleList.get(0);
		else
			return null;
	}

	/**
	 * @Description 通过编码找到对应的模块
	 * @param moduleCode
	 * @param statue
	 * @return
	 */
	public TbBbsModule getModuleByCode(String moduleCode, String statue) {
		String hql = "from TbBbsModule as tbm where tbm.code=? and tbm.statue=? ";
		List moduleList = this.dao.find(hql,
				new Object[] { moduleCode, statue });

		if (moduleList != null && moduleList.size() != 0)
			return (TbBbsModule) moduleList.get(0);
		else
			return null;

	}
	
	
	public TbBbsModule getModuleByCodes(String moduleCode) {
		String hql = "from TbBbsModule as tbm where tbm.code=? ";
		List moduleList = this.dao.find(hql,
				new Object[] { moduleCode});

		if (moduleList != null && moduleList.size() != 0)
			return (TbBbsModule) moduleList.get(0);
		else
			return null;

	}

	@Override
	public List<TbBbsModule> getChildModule(String moduleNo) {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * @Description 将pojo转换成DTO
	 * @param tbm
	 * @return
	 */
	public BbsModuleDTO getDtoFromBean(TbBbsModule tbm) {
		BbsModuleDTO bbsModuleDTO = new BbsModuleDTO();
		bbsModuleDTO.setModuleName(tbm.getModuleName());
		if (tbm.getDescription() != null)
			bbsModuleDTO.setDescription(tbm.getDescription());
		bbsModuleDTO.setParent(tbm.getParent());
		TbBbsModule tbmTemp = getModuleByCode(tbm.getParent(),
				Constant.MODULE_ABLE);
		bbsModuleDTO.setParentName(tbmTemp.getModuleName()); // 存储父模块名字到Dto中
		bbsModuleDTO.setCode(tbm.getCode());
		bbsModuleDTO.setParentURL(tbmTemp.getUrlId());
		bbsModuleDTO.setUrlId(tbm.getUrlId());
		return bbsModuleDTO;

	}

	/**
	 * @Description 将TbBbsModule 集合转换成 BbsModuleDTO
	 * @param list
	 * @param conList
	 */
	private void forEach(List<TbBbsModule> list, List<BbsModuleDTO> conList) {
		BbsModuleDTO bbsModuleDTO = null;
		for (TbBbsModule bbsModule : list) {
			bbsModuleDTO = new BbsModuleDTO();
			bbsModuleDTO.setModuleName(bbsModule.getModuleName());
			if (bbsModule.getDescription() != null)
				bbsModuleDTO.setDescription(bbsModule.getDescription());
			bbsModuleDTO.setParent(bbsModule.getParent());

			bbsModuleDTO.setCode(bbsModule.getCode());
			if (bbsModule.getUrlId() != null)
				bbsModuleDTO.setUrlId(bbsModule.getUrlId());
			conList.add(bbsModuleDTO);
		}

	}

	/**
	 * 
	 * @Description 初始化Module信息
	 * @return
	 */
	public List initModuleInfo(PostServiceImpl postservice,
			RoleService roleService, UserService userService,
			ReplyServiceImpl replyService, String moduleName, String parent) {
		List parentModule = null;
		String hql = null;
		String param = null;
		if (moduleName != null) {
			param = moduleName;
			hql = "from TbBbsModule tb where tb.moduleName=? and tb.statue=?"; // 查询可用的父模块
		} else {
			param = parent;
			hql = "from TbBbsModule tb where tb.parent=? and tb.statue=?"; // 查询可用的父模块
		}
		parentModule = dao.find(hql, new Object[] { param, "SOA" }); // 查的父模块信息
		System.out.println("parentModuleSize:" + parentModule.size());
		List parentModuleList = null;
		if (parentModule != null && parentModule.size() > 0) {
			InitParentModuleDTO moduleDTO = null;
			parentModuleList = new ArrayList();
			for (int i = 0; i < parentModule.size(); i++) { // 遍历父模块信息
				TbBbsModule tb = (TbBbsModule) parentModule.get(i); // 取得第i个父模块对象
				moduleDTO = new InitParentModuleDTO(); // 创建一个新的父类ModuleDto,并将父类信息存进去
				moduleDTO.setModuleId(tb.getId().toString());
				moduleDTO.setModuleName(tb.getModuleName());
				moduleDTO.setModuleCode(tb.getCode());
				/** 基本信息存储完毕 **/
				moduleDTO.setModuleURI(tb.getUrlId());
				// moduleDTO.setPostCount(postCount); /**存储对应模块帖子总数**/;
				// moduleDTO.setReplyCount(replyCount); /**存储对应大模块回帖总数**/
				System.out.println("code:" + tb.getCode() + "statue:"
						+ tb.getStatue());
				TbSysRole parentRole = roleService.queryTbSysRoleByModuleId(tb
						.getId(), "SOA");
				if (parentRole != null) {
					TbSysUser parentUser = userService.queryUserInfo(parentRole
							.getId());
					if (parentUser != null) {
						moduleDTO.setModuleManager(parentUser.getUserName());

						moduleDTO.setModuleManagerId(parentUser.getId()
								.toString());
					}
				}
				List childList = queryChildModule(tb.getCode(), tb.getStatue()); // 查询父模块下的
				InitModuleDTO childModuleDTO = null;

				if (childList != null && childList.size() > 0) { // 子模块不为空，且大小大于0

					TbBbsModule childTb = null;
					List childModuleDTOList = new ArrayList();
					for (int j = 0; j < childList.size(); j++) { // 遍历子模块
						childModuleDTO = new InitModuleDTO();
						childTb = (TbBbsModule) childList.get(j);
						childModuleDTO.setModuleCode(childTb.getCode()); // 设置module代码
						childModuleDTO.setModuleId(childTb.getId().toString());
						childModuleDTO.setModuleName(childTb.getModuleName());
						childModuleDTO.setModuleURI(childTb.getUrlId());
						if (childTb.getDescription() != null) {
							childModuleDTO.setModuleRemark(childTb
									.getDescription());
						}
						List postList = postservice.queryPostByModuleId(childTb
								.getId()); // 通过模块号查询帖子总数
						if (postList != null) {
							childModuleDTO.setPostCount(String.valueOf(postList
									.size())); // 获取帖子总数

							TbBbsPost post = null;
							int count = 0; // 初始化一个统计帖子回帖总数

							for (int k = 0; k < postList.size(); k++) {
								post = (TbBbsPost) postList.get(k);
								count += post.getTbBbsReplies().size(); // 想加
							}
							System.out.println("count:" + count);
							childModuleDTO.setReplyCount(String.valueOf(count)); // 获取回帖总数
						}
						/** 计算当天帖子数=发帖数+回帖数 **/
						int postAndReplycount = 0;
						Date date = new Date(); // 当前系统产生一个时间
						Date startDate = DateFormatUtils
								.convertStringToDate(DateFormatUtils
										.convertDateToString(date));
						Long tempTime = date.getTime()
								+ DateFormatUtils.getDateTime();
						Date endDateTemp = new Date(tempTime);
						Date endDate = DateFormatUtils
								.convertStringToDate(DateFormatUtils
										.convertDateToString(endDateTemp));
						System.out
								.println("************************/nstartDate: "
										+ startDate + "endDate:" + endDate);
						List dayPostList = postservice.queryPostByDate(
								startDate, endDate, childTb.getId());
						List dayReplyList = replyService.queryReplyByDate(
								startDate, endDate, childTb.getId());
						if (dayPostList != null) {
							postAndReplycount += dayPostList.size();
						}
						if (dayReplyList != null) {
							postAndReplycount += dayReplyList.size();
						}
						childModuleDTO.setDayPostCount(String
								.valueOf(postAndReplycount)); // 设置日帖子总数
						/** 统计对应子模块下的帖子数 **/
						TbBbsPost lastPost = postservice
								.queryPostByModuleCode(childTb.getId()); // 取得该模块下最后近一次帖子更新信息
						if (lastPost != null) {
							childModuleDTO.setLastPublishArticleId(lastPost
									.getId().toString()); // 设置最后发表文章的ID
							TbBbsReply reply = replyService.queryReplyByPostId(
									lastPost, lastPost.getLastReplyTime());
							if (reply != null) {
								childModuleDTO.setLastPublishAuthor(reply
										.getTbSysUser().getUserName()); // 设置最后发表作者姓名
							} else {
								childModuleDTO.setLastPublishAuthor(lastPost
										.getTbSysUser().getUserName());
							}
							childModuleDTO.setLastPublishTime(DateFormatUtils
									.convertDateTimeToString(lastPost
											.getLastReplyTime())); // 设置最后一次发布时间
							childModuleDTO.setLastPublishTitle(lastPost
									.getTitle()); // 设置最后一次发表文章的标题
							childModuleDTO.setLastPublishAuthorId(lastPost
									.getLastReplyNo().toString()); // 设置最后一次发表的作者ID

						}
						// System.out.println("childTB:"+childTb.getId());
						TbSysRole role = roleService.queryTbSysRoleByModuleId(
								childTb.getId(), "SOA");
						if (role != null) { // 角色不为空情况下添加版主信息
							System.out.println(role.getRole());

							TbSysUser user = userService.queryUserInfo(role
									.getId());
							if (user != null) {
								childModuleDTO.setModuleManager(user
										.getUserName()); // 设置版主
								System.out.println(user.getUserName());
								childModuleDTO.setModuleManagerId(user.getId()
										.toString());// 设置版主ID
							}
						}
						childModuleDTOList.add(childModuleDTO);
					}
					moduleDTO.setChildModule(childModuleDTOList);
					System.out.println(moduleDTO.getChildModule().size());
				}
				parentModuleList.add(moduleDTO); // 添加封装后的父模块信息
			}
		}
		return parentModuleList;

	}

	/**
	 * 
	 * @Description 初始化论坛统计数比如：当天回帖发帖总数等
	 * @return
	 */
	public InitModuleCountInfoDTO queryTotalBbsCountInfo(
			UserService userService, ReplyServiceImpl replyServiceImpl,
			PostServiceImpl postServiceImpl) {
		InitModuleCountInfoDTO moduleInfoDTO = new InitModuleCountInfoDTO(); // 产生一个初始化所有论坛信息Dto
		int dayMaxPostCount = postServiceImpl.totalMaxPostCount(); // 获得历史某天最高发帖量
		moduleInfoDTO.setDayMaxPostCount(dayMaxPostCount);
		int vipCount = userService.totalCount(); // 统计会员总量
		moduleInfoDTO.setVipCount(vipCount);
		/***** 产生当天、昨天时间 ****/
		Date date = new Date(); // 当前系统产生一个时间
		Date startDate = DateFormatUtils.convertStringToDate(DateFormatUtils
				.convertDateToString(date));
		Long lTempTime = date.getTime() + DateFormatUtils.getDateTime(); // 当天
		Long bTempTime = date.getTime() - DateFormatUtils.getDateTime(); // 昨天
		Date endDateTemp = new Date(lTempTime);
		Date beforeDateTemp = new Date(bTempTime);
		Date beforeDate = DateFormatUtils.convertStringToDate(DateFormatUtils
				.convertDateToString(beforeDateTemp)); // 昨天
		Date endDate = DateFormatUtils.convertStringToDate(DateFormatUtils
				.convertDateToString(endDateTemp)); // 今天
		System.out.println("************************/nstartDate: " + startDate
				+ " endDate:" + endDate + " beforeDate:" + beforeDate);
		/** end **/
		/*** 发帖情况：当天、前天 **/
		Integer dayPostCount = postServiceImpl.totalCountPostByDate(startDate,
				endDate); // 获取当天发帖总数,即今天
		Integer beforeDayPostCount = postServiceImpl.totalCountPostByDate(
				beforeDate, endDate); // 获取前一天的发帖总数
		/** end **/
		/** 回帖情况：当天、前天 **/
		Integer dayReplyCount = replyServiceImpl.totalCountByDate(startDate,
				endDate); // 获得当天回帖情况、即今天
		Integer beforeDayReplyCount = replyServiceImpl.totalCountByDate(
				beforeDate, startDate); // 获得前一天回帖情况
		/** end **/
		/** 以下为当天、前天发帖+回帖数量 **/
		Integer dayCount = dayPostCount + dayReplyCount; // 当天
		moduleInfoDTO.setDayPostAndReplyCount(dayCount);
		Integer beforeDayCount = beforeDayPostCount + beforeDayReplyCount; // 前一天
		moduleInfoDTO.setYesterdayPostAndReplyCount(beforeDayCount);
		/** end **/
		/** 论坛发帖、回帖情况 **/
		Integer allReplyCount = replyServiceImpl.allReplyCount(); // 所有回帖
		moduleInfoDTO.setTotalReplyCount(allReplyCount);
		Integer allPostCount = postServiceImpl.allPostCount(); // 所有发帖
		moduleInfoDTO.setTotalPostCount(allPostCount);
		return moduleInfoDTO;

	}

	/**
	 * 
	 * @Description 初始化论坛置顶模块统计数比如：当天回帖发帖总数等
	 * @return
	 */
	public InitModuleCountInfoDTO queryTotalModuleCountInfo(
			UserService userService, ReplyServiceImpl replyServiceImpl,
			PostServiceImpl postServiceImpl, String moduleName) {
		InitModuleCountInfoDTO moduleInfoDTO = new InitModuleCountInfoDTO(); // 产生一个初始化所有论坛信息Dto
		TbBbsModule module = getModule(moduleName, "SOA"); // 取得名为moduleName的对象
		int dayMaxPostCount = 0;
		List childModuleList = queryChildModule(module.getCode(), "SOA");
		StringBuffer hql = null;
		if (childModuleList != null && childModuleList.size() > 0) { // 遍历
			StringBuffer hqlTemp = new StringBuffer("in ('");
			for (int k = 0; k < childModuleList.size(); k++) {
				TbBbsModule moduleTemp = (TbBbsModule) childModuleList.get(0);
				hqlTemp.append(moduleTemp.getId() + "','");
			}
			hql = new StringBuffer(hqlTemp.toString().substring(0,
					hqlTemp.toString().length() - 2));
			hql.append(")");
			System.out.println("SLQ*******************print:" + hql.toString());
		}
		dayMaxPostCount = postServiceImpl.totalMaxPostCountByModuleId(hql
				.toString(), module.getCode()); // 获得历史某天最高发帖量
		moduleInfoDTO.setDayMaxPostCount(dayMaxPostCount);
		int vipCount = userService.totalCount(); // 统计会员总量
		moduleInfoDTO.setVipCount(vipCount);
		/***** 产生当天、昨天时间 ****/
		Date date = new Date(); // 当前系统产生一个时间
		Date startDate = DateFormatUtils.convertStringToDate(DateFormatUtils
				.convertDateToString(date));
		Long lTempTime = date.getTime() + DateFormatUtils.getDateTime(); // 当天
		Long bTempTime = date.getTime() - DateFormatUtils.getDateTime(); // 昨天
		Date endDateTemp = new Date(lTempTime);
		Date beforeDateTemp = new Date(bTempTime);
		Date beforeDate = DateFormatUtils.convertStringToDate(DateFormatUtils
				.convertDateToString(beforeDateTemp)); // 昨天
		Date endDate = DateFormatUtils.convertStringToDate(DateFormatUtils
				.convertDateToString(endDateTemp)); // 今天
		System.out.println("************************/nstartDate: " + startDate
				+ " endDate:" + endDate + " beforeDate:" + beforeDate);
		/** end **/
		/*** 发帖情况：当天、前天 **/
		Integer dayPostCount = postServiceImpl.totalCountPostByModuleAndDate(
				startDate, endDate, module.getCode()); // 获取当天发帖总数,即今天
		Integer beforeDayPostCount = postServiceImpl
				.totalCountPostByModuleAndDate(beforeDate, endDate, module
						.getCode()); // 获取前一天的发帖总数
		/** end **/
		/** 回帖情况：当天、前天 **/
		List postList = postServiceImpl.totalPostCountByParentModuleCode(module
				.getCode()); // 取得帖子总集合

		Integer dayReplyCount = 0;
		Integer beforeDayReplyCount = 0;
		if (postList != null) {
			for (int i = 0; i < postList.size(); i++) {
				dayReplyCount += replyServiceImpl.totalCountByModuleAndDate(
						startDate, endDate, module.getCode()); // 获得当天回帖情况、即今天
				beforeDayReplyCount += replyServiceImpl
						.totalCountByModuleAndDate(beforeDate, startDate,
								module.getCode()); // 获得前一天回帖情况
			}
		}
		/** end **/
		/** 以下为当天、前天发帖+回帖数量 **/
		Integer dayCount = dayPostCount + dayReplyCount; // 当天
		moduleInfoDTO.setDayPostAndReplyCount(dayCount);
		Integer beforeDayCount = beforeDayPostCount + beforeDayReplyCount; // 前一天
		moduleInfoDTO.setYesterdayPostAndReplyCount(beforeDayCount);
		/** end **/
		/** 论坛发帖、回帖情况 **/
		Integer allReplyCount = replyServiceImpl.totalCountByModule(module
				.getCode()); // 所有回帖
		moduleInfoDTO.setTotalReplyCount(allReplyCount);
		if (postList != null) {
			moduleInfoDTO.setTotalPostCount(postList.size()); // 所有发帖
		} else {
			moduleInfoDTO.setTotalPostCount(0);
		}
		return moduleInfoDTO;

	}
	
	
	
	
	public ModuleBean getModuleStatue(){
		         List moduleList=dao.find("from TbBbsModule tb where tb.code='01_' and tb.statue='SOX'"); //查询技术板块是否禁用
		         List parentList=null;
		         List tempList=null;
		         List childList=null;
		         ModuleBean moduleBean=new ModuleBean();
		          if(moduleList!=null&&moduleList.size()>0){  //父模块被禁用
		        	TbBbsModule module= (TbBbsModule)moduleList.get(0);
		        	parentList=new ArrayList();
		        	parentList.add(module.getCode());
		        	 
		        	  moduleBean.setModuleTh(parentList);
		        	  tempList=  dao.find("from TbBbsModule tb where tb.parent='01_'");
		        	
		        	if(tempList!=null&&tempList.size()>0){   //父模块禁用,回显所有子模块均为禁用
		        		childList=new ArrayList();
		        		for(int i=0;i<tempList.size();i++){
		        			TbBbsModule module1=(TbBbsModule)tempList.get(i);
		        			childList.add(module1.getCode().toString());
		        		}
		        		moduleBean.setThChildModule(childList);
		        		
		        	}
		          }else{  //非禁用
		        	  System.out.println("非禁用模式！！！！1");
		        	  String hql="from TbBbsModule tb where tb.parent='01_' and tb.statue='SOX'";
		              tempList=dao.find(hql);
		             
		        	  if(tempList!=null){
		        		  childList=new ArrayList();
		        		  for(int k=0;k<tempList.size();k++){
		        			  TbBbsModule module1=(TbBbsModule)tempList.get(k);
			        			childList.add(module1.getCode().toString());
			        			 
		        		  }
		        			moduleBean.setThChildModule(childList);
		        	  }
		        	  
		          }
		         /**基本面板**/
		          List moduleList1=dao.find("from TbBbsModule tb where tb.code='02_' and tb.statue='SOX'"); //查询技术板块是否禁用
			         List parentList1=null;
			         List tempList1=null;
			         List childList1=null;
			       
			          if(moduleList1!=null&&moduleList1.size()>0){  //父模块被禁用
			        	  
			        	TbBbsModule module= (TbBbsModule)moduleList1.get(0);
			        	parentList1=new ArrayList();
			        	parentList1.add(module.getCode().toString());
			        	  moduleBean.setBaseModule(parentList1);
			        	  tempList1=  dao.find("from TbBbsModule tb where tb.parent='02_'");
			        	
			        	if(tempList1!=null&&tempList1.size()>0){   //父模块禁用,回显所有子模块均为禁用
			        		childList1=new ArrayList();
			        		for(int i=0;i<tempList1.size();i++){
			        			TbBbsModule module1=(TbBbsModule)tempList1.get(i);
			        			childList1.add(module1.getCode().toString());
			        		}
			        		moduleBean.setBaseChildModule(childList1);
			        		
			        	}
			          }else{  //非禁用
			        	 
			        	  String hql="from TbBbsModule tb where tb.parent='02_' and tb.statue='SOX'";
			              tempList1=dao.find(hql);
			              
			        	  if(tempList1!=null){
			        		  childList1=new ArrayList();
			        		  for(int k=0;k<tempList1.size();k++){
			        			  TbBbsModule module1=(TbBbsModule)tempList1.get(k);
				        			childList1.add(module1.getCode().toString());
				        			 
			        		  }
			        			moduleBean.setBaseChildModule(childList1);
			        	  }
			        	  
			          }
		        /**实战贴图**/
			          List moduleList2=dao.find("from TbBbsModule tb where tb.code='03_' and tb.statue='SOX'"); //查询技术板块是否禁用
				         List parentList2=null;
				         List tempList2=null;
				         List childList2=null;
				          System.out.println("SDASADSA"+moduleList2.size());
				          if(moduleList2!=null&&moduleList2.size()>0){  //父模块被禁用
				        	 
				        	TbBbsModule module= (TbBbsModule)moduleList2.get(0);
				        	parentList2=new ArrayList();
				        	parentList2.add(module.getCode().toString());
				        	  moduleBean.setSmodule(parentList2);
				        	  
				        	  tempList2=  dao.find("from TbBbsModule tb where tb.parent='03_'");
				        	 
				        	if(tempList2!=null&&tempList2.size()>0){   //父模块禁用,回显所有子模块均为禁用
				        	 
				        		childList2=new ArrayList();
				        		for(int i=0;i<tempList2.size();i++){
				        			TbBbsModule module1=(TbBbsModule)tempList2.get(i);
				        			 
				        			childList2.add(module1.getCode().toString());
				        			 
				        		}
				        		moduleBean.setSchildModule(childList2);
				        		
				        	}
				          }else{  //非禁用
				        	  
				        	  String hql="from TbBbsModule tb where tb.parent='03_' and tb.statue='SOX'";
				              tempList2=dao.find(hql);
				              
				        	  if(tempList2!=null){
				        		  childList2=new ArrayList();
				        		  for(int k=0;k<tempList2.size();k++){
				        			  TbBbsModule module1=(TbBbsModule)tempList2.get(k);
					        			childList2.add(module1.getCode().toString());
					        			 
				        		  }
				        			moduleBean.setSchildModule(childList2);
				        	  }
				        	  
				          }   
			          /**书籍**/
				         
				          List moduleList3=dao.find("from TbBbsModule tb where tb.code='04_' and tb.statue='SOX'"); //查询技术板块是否禁用
					         List parentList3=null;
					         List tempList3=null;
					         List childList3=null;
					         
					          if(moduleList3!=null&&moduleList3.size()>0){  //父模块被禁用
					        	 
					        	TbBbsModule module= (TbBbsModule)moduleList3.get(0);
					        	parentList3=new ArrayList();
					        	parentList3.add(module.getCode().toString());
					        	  moduleBean.setBmodule(parentList3);
					        	  
					        	  tempList3=  dao.find("from TbBbsModule tb where tb.parent='04_'");
					        	  System.out.println(tempList3.size());
					        	if(tempList3!=null&&tempList3.size()>0){   //父模块禁用,回显所有子模块均为禁用
					        		 
					        		childList3=new ArrayList();
					        		for(int i=0;i<tempList3.size();i++){
					        			TbBbsModule module1=(TbBbsModule)tempList3.get(i);
					        			 
					        			childList3.add(module1.getCode().toString());
					        			 
					        		}
					        		moduleBean.setBchildModule(childList3);
					        		
					        	}
					          }else{  //非禁用
					        	  
					        	  String hql="from TbBbsModule tb where tb.parent='04_' and tb.statue='SOX'";
					              tempList3=dao.find(hql);
					               
					        	  if(tempList3!=null){
					        		  childList3=new ArrayList();
					        		  for(int k=0;k<tempList3.size();k++){
					        			  TbBbsModule module1=(TbBbsModule)tempList3.get(k);
						        			childList3.add(module1.getCode().toString());
						        		 
					        		  }
					        			moduleBean.setBchildModule(childList3);
					        	  }
					        	  
					          }   
				          /**站务**/
					          List moduleList4=dao.find("from TbBbsModule tb where tb.code='05_' and tb.statue='SOX'"); //查询技术板块是否禁用
						         List parentList4=null;
						         List tempList4=null;
						         List childList4=null;
						          
						          if(moduleList4!=null&&moduleList4.size()>0){  //父模块被禁用
						        	 
						        	TbBbsModule module= (TbBbsModule)moduleList4.get(0);
						        	parentList4=new ArrayList();
						        	parentList4.add(module.getCode().toString());
						        	  moduleBean.setMmodule(parentList4);
						        	  
						        	  tempList4=  dao.find("from TbBbsModule tb where tb.parent='05_'");
						        	 
						        	if(tempList4!=null&&tempList4.size()>0){   //父模块禁用,回显所有子模块均为禁用
						        		 
						        		childList4=new ArrayList();
						        		for(int i=0;i<tempList4.size();i++){
						        			TbBbsModule module1=(TbBbsModule)tempList4.get(i);
						        			 
						        			childList4.add(module1.getCode().toString());
						        			 
						        		}
						        		moduleBean.setMchildModule(childList4);
						        		
						        	}
						          }else{  //非禁用
						        	  
						        	  String hql="from TbBbsModule tb where tb.parent='05_' and tb.statue='SOX'";
						              tempList4=dao.find(hql);
						              System.out.println(tempList4.size());
						        	  if(tempList4!=null){
						        		  childList4=new ArrayList();
						        		  for(int k=0;k<tempList4.size();k++){
						        			  TbBbsModule module1=(TbBbsModule)tempList4.get(k);
							        			childList4.add(module1.getCode().toString());
							        			 
						        		  }
						        			moduleBean.setMchildModule(childList4);
						        	  }
						        	  
						          }  
		        return moduleBean;
		
	}
	
	
	/**
	 * 
	 * @Description   更新模块状态
	 * @param parentCode
	 */
  public void updateModuleStatue(TbBbsModule module){
	     dao.update(module);
	  
  }
}
